<!DOCTYPE html>
<html>
<head>
    <title>门诊医生--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/pagination.js"></script>
    <link rel="stylesheet" type="text/css" href="../Css/pagination.css" />

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">

        $(function () {
            $('#newNav').click(function () {
                window.location.href = "add.html";
            });
            //初始化数据
            initData("", "", "");
        });

        function initData(doctorId, userName, keShi) {
            $.ajax({
                url: "queryDoctor",
                data: {'doctorId': doctorId, "userName": userName, 'keShi': keShi},
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    //清空下级标签
                    $("#xunhuan").empty();
                    let page = data.data.doctorPage;
                    let param = data.data.param;
                    let list = page.list;
                    //遍历数据
                    $.each(list, function (index, doctor) {
                        $("#xunhuan").append(
                            "<tr >\n" +
                            "\t<td style=\"vertical-align:middle;\"><input type=\"checkbox\" name=\"check\" value=\"" + doctor.dId + "\"></td>\n" +
                            "    <td style=\"vertical-align:middle;\">" + doctor.dId + "</td>\n" +
                            "    <td style=\"vertical-align:middle;\">" + doctor.dName + "</td>\n" +
                            "    <td style=\"vertical-align:middle;\">" + formDate(doctor.dIntime) + "</td>\n" +
                            "    <td style=\"vertical-align:middle;\">" + doctor.dKeshi + "</td>\n" +
                            "    <td style=\"vertical-align:middle;\"><a href=\"look.html?did=" + doctor.dId + "\">详情>>></a>&nbsp;&nbsp;&nbsp;<a href=\"edit.html?did=" + doctor.dId + "\">更改</a></td>\n" +
                            "</tr>")
                    });

                    //查询参数回显
                    $("#keShi").val(param.keShi);
                    $("#doctorId").val(param.doctorId);
                    $("#userName").val(param.userName);

                    //分页
                    // $("#pageNum").text(page.pageNum + "/" + page.pages);
                    // $("#totalMsg").text(page.pages);


                    new Pagination({
                        element: '#pages',
                        type: 2,
                        layout: 'prev, pager, next, total, jumper',
                        pageIndex: 1,
                        pageSize: 5,
                        pageCount: 9,
                        total: page.total,
                        singlePageHide: false,
                        disabled: true,
                        currentChange: function (index) {
                            console.log(index);

                            let doctorId = $("#doctorId").val();
                            let userName = $("#userName").val();
                            let keShi = $("#keShi").val();
                            $.ajax({
                                url: "queryDoctor",
                                data: {'doctorId': doctorId, "userName": userName, 'keShi': keShi,'pageNum':index},
                                type: 'post',
                                dataType: 'json',
                                success: function (data) {
                                    //清空下级标签
                                    $("#xunhuan").empty();
                                    let page = data.data.doctorPage;
                                    let param = data.data.param;
                                    let list = page.list;
                                    //遍历数据
                                    $.each(list, function (index, doctor) {
                                        $("#xunhuan").append(
                                            "<tr >\n" +
                                            "\t<td style=\"vertical-align:middle;\"><input type=\"checkbox\" name=\"check\" value=\"" + doctor.dId + "\"></td>\n" +
                                            "    <td style=\"vertical-align:middle;\">" + doctor.dId + "</td>\n" +
                                            "    <td style=\"vertical-align:middle;\">" + doctor.dName + "</td>\n" +
                                            "    <td style=\"vertical-align:middle;\">" + formDate(doctor.dIntime) + "</td>\n" +
                                            "    <td style=\"vertical-align:middle;\">" + doctor.dKeshi + "</td>\n" +
                                            "    <td style=\"vertical-align:middle;\"><a href=\"look.html?did=" + doctor.dId + "\">详情>>></a>&nbsp;&nbsp;&nbsp;<a href=\"edit.html?did=" + doctor.dId + "\">更改</a></td>\n" +
                                            "</tr>")
                                    });
                                }
                            });
                        }
                    });

                }
            });
        }

        function queryDoctor() {
            let doctorId = $("#doctorId").val();
            let userName = $("#userName").val();
            let keShi = $("#keShi").val();
            initData(doctorId, userName, keShi);
        }

        function formDate(toDate) {
            var date = new Date(toDate);
            var year = date.getFullYear(); //获取当前年份
            var mon = date.getMonth() + 1; //获取当前月份
            var da = date.getDate(); //获取当前日
            var day = date.getDay(); //获取当前星期几
            var h = date.getHours(); //获取小时
            var m = date.getMinutes(); //获取分钟
            var s = date.getSeconds(); //获取秒
            var d = document.getElementById('Date');
            return year + '-' + mon + '-' + da;
        }

        function checkall() {
            var alls = document.getElementsByName("check");
            var ch = document.getElementById("checkall");
            if (ch.checked) {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = true;
                }
            } else {
                for (var i = 0; i < alls.length; i++) {
                    alls[i].checked = false;
                }
            }
        }

        function delAll() {
            var alls = document.getElementsByName("check");
            var ids = new Array();
            for (var i = 0; i < alls.length; i++) {
                if (alls[i].checked) {
                    ids.push(alls[i].value);
                }
            }
            if (ids.length > 0) {
                if (confirm("确认操作?")) {
                    alert("成功!");
                }
            } else {
                alert("请选中要操作的项");
            }
        }

        //导出excel
        function exportExcel() {
            var ids = [];
            $("input[name='check']:checked").each(function (i) {
                ids.push($(this).val())
                //$("body").append("<p>"+$(this).val()+"</p>")
            })
            //console.log(ids)
            if (ids.length > 0) {
                $.ajax({
                    url: "exportExcelDoctor",
                    data: {"doctorIds": ids},
                    traditional: true,
                    success: function (resp) {
                        if (resp.response.flag) {
                            window.location.href = "http://localhost:8080/downloadFile?fileName=doctorMsg.xls"
                        } else {

                        }
                    }
                })
            } else {
                alert("请选择要导出的数据");
            }
        }

        //批量刪除
        function delDoctor() {
            var ids = [];
            $("input[name='check']:checked").each(function (i) {
                ids.push($(this).val())
                // $("body").append("<p>"+$(this).val()+"</p>")
            })
            //console.log(ids)
            if (ids.length > 0) {
                $.ajax({
                    url: "deleteDoctorByIds",
                    data: {"doctorIds": ids},
                    traditional: true,
                    success: function (resp) {
                        if (resp.response.flag) {
                            initData("", "", "")
                        } else {
                            alert("删除失败")
                        }
                    }
                })
            } else {
                alert("请选择要导出的数据");
            }
        }

        function restPage() {
            let doctorId = $("#doctorId").val("");
            let userName = $("#userName").val("");
            let keShi = $("#keShi").val("");
            initData("", "", "")
        }
    </script>
</head>
<body>

<form action="#" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">医生编号：</td>
            <td><input id="doctorId" type="text" name="doctorId" value=""/></td>

            <td width="10%" class="tableleft">医生姓名：</td>
            <td><input id="userName" type="text" name="userName" value=""/></td>

            <td width="10%" class="tableleft">科室：</td>
            <td><input id="keShi" type="text" name="keShi" value=""/></td>
        </tr>
        <tr>
            <td colspan="6">
                <center>
                    <input class="btn btn-primary" type="button" onclick="queryDoctor()" value="查询"/>
                    <input type="button" class="btn btn-primary" onclick="restPage()" value="清空"/>
                </center>
            </td>
        </tr>
    </table>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th><input type="checkbox" id="checkall" onChange="checkall()"></th>
        <th>医生编号</th>
        <th>医生姓名</th>
        <th>入院时间</th>
        <th>所属科室</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="xunhuan">
    <tr>
        <td style="vertical-align:middle;"><input type="checkbox" name="checkAll" value="1"></td>
        <td style="vertical-align:middle;">1103</td>
        <td style="vertical-align:middle;">程俊</td>
        <td style="vertical-align:middle;">2015-09-09 12：12：12</td>
        <td style="vertical-align:middle;">血液科</td>
        <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a>
        </td>
    </tr>
    </tbody>
</table>

<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <th colspan="5">
            <div class="inline pull-right page" id="pages">
                <!--                <a id="firstPage" href='#'>第一页</a> <a id="prePage" href='#' disabled="disabled">上一页</a>-->
                <!--                <span class='current'>1</span><a href='#'>2</a><a-->
                <!--                    href='/chinapost/index.php?m=Label&a=index&p=3'>3</a><a href='#'>4</a><a href='#'>5</a>-->
                <!--                <a id="nextPage" href='#'>下一页</a> <a id="endPage" href='#'>最后一页</a>-->
                <!--                &nbsp;&nbsp;&nbsp;共<span id="totalMsg" class='current'>32</span>条记录<span id="pageNum" class='current'> 1/33 </span>页-->
            </div>
            <div>
                <button type="button" class="btn btn-success" id="newNav">添加新医生</button>
                <button class="btn btn-success" id="delDoctor" onclick="delDoctor()">删除选中</button>
                <button class="btn btn-success" id="exportDoctor" onclick="exportExcel()">导出Excel</button>
            </div>
        </th>
    </tr>
</table>

</body>
</html>
